<!-- 以下內容用於保存草稿 -->

 <script type="text/javascript">
<!--
function showValues() {
    var fields = $(":input").serializeArray();
    $("#results").empty();
    $.each(fields, function(i, field){
      $("#results").append(field.name+":"+addSlash(field.value) + "|#-#-#-#|");
    });
//    $("#Article_arc_result").val($("#results").html());
    
  }

  function addSlash(val){
		val = val.replace(/:/g,"\\:");
		val = val.replace(/;/g,"\\;");

//		alert(val);
		return val;
  }

  

  function AutoSave(){
		$.post("<?php echo $this->createUrl('saveasfile');?>",{"message":$("#results").html()},function(msg){
			$("#autosave").html(msg);
		});

		setInterval("AutoSave()",60000);
  }

//  function Hello(){
//
//	var today = new Date();
//	$("#result").val(today.toString());
//
//	
//
////	$.post("<?php echo $this->createUrl('file/saveinfoasfile');?>",{"message":$("#results").html()},function(msg){
////		alert(msg);
////	});
////	setInterval("Hello()",1000);
//  }
  
 

//-->
</script>

<?php 

 	$add_category_url = $this->createUrl('category/createremote');
 	$add_category_type = Category::CATEGORY_NEWS;
 	
	$ready = <<<READY
	
	//以下內容用於自動保存文章信息
	/***BEGIN***/
	 AutoSave();  
	 

	 
	 
//	$(":checkbox").click(showValues); 
    $("select").change(showValues); 
    $(":input").change(showValues);
	 
	 showValues();
	 /***END**/ 
	 
	
	var str = "这里填写文章标题";
	$("#Article_arc_title").val(str).focus(function(){
		if($(this).val()==str){
			$(this).val("");
		}		
	});

	$(".category input[type=checkbox]").change(function(){
//		alert($(this).val());
		var str = "";
		$(".category input[type=checkbox]").each(function(){
			if($(this).attr("checked") == true){
				str += ","+$(this).val();
			}
		});

		str = str.substring(1,str.length);
		$("#arc_cids").val(str);

	});

	$("#arc_submit").button();
	$("#get_tag").button();
	$("#add_category").button();
	
	$("#add_category").click(function(){
		$.post("$add_category_url",{
			'cate_pid':$("#Article_arc_cid").val(),
			'cate_name':$("#categoryName").val(),
			'cate_type':$add_category_type
		},function(msg){
//			alert(msg);
			$(".category").append(msg);
		});
	});
READY;

$analysis_url = $this->createUrl('analysis');
$head_js = <<<HEAD
	function showNext(object){
		object.next().slideToggle("slow");
		return false;
	}
	function getTag(){
	//	alert("Hello");
	//	content = $(document.getElementsByTagName('iframe')[0].contentWindow.document.body).html();
	//	content = $("#el-rte-editor").contents().find("body").html();
	//	content = $(document.getElementsByTagName('iframe')[0]).contents().find("body").html();
		content = $("#Article_arc_content").val();
//		alert(content);
		
		$.post('$analysis_url',{'content':content},function(msg){
			$("#Article_arc_tags").val(msg);
//			alert(msg);
		});
	}
HEAD;
?>

<?php Yii::app()->getClientScript()->registerScript('news-admin-create-ready',$ready,CClientScript::POS_READY);?>
<?php Yii::app()->getClientScript()->registerScript('news-admin-create-heade',$head_js,CClientScript::POS_HEAD);?>
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'article-form',
	'enableAjaxValidation'=>true,
)); ?>
<div id="results" style="display:none;">result</div>
<div class="column1 form" style="width:68%;">
<div class="box">
	<?php $this->beginWidget('zii.widgets.CPortlet', array('title'=>CHtml::image($this->module->registerImage('article.png'),'Logo', array('width'=>'20')).'&nbsp;&nbsp;增加新文章'.$html,	));?>
		<div class="box-content">		
			<div class="hide">&nbsp;<span id="autosave"></span></div>
			<?php echo Yii::t('admin','<p class="note">Fields with <span class="required">*</span> are required.</p>');?>	

			<?php echo $form->errorSummary($model); ?>
		
	
			<?php echo $this->renderPartial('_form', array('model'=>$model,'form'=>$form)); ?>
		</div>
	<?php $this->endWidget();?>	
</div>
</div>
<div class="column2 form" style="margin-left:70%;width:32%;">
	<textarea rows="3" style="display:none;" cols="20" id="Article_arc_result" name="Article[arc_result]">

	</textarea>
<div class="box">
	<?php $this->beginWidget('zii.widgets.CPortlet', array('title'=>CHtml::image($this->module->registerImage('article.png'),'Logo', array('width'=>'20')).'&nbsp;&nbsp;'.Yii::t('article','Publish')));?>
		<div class="box-content">
    	<div class="row">
    		State*：&nbsp;&nbsp;<span id="statelabel">PUBLIISHED</span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void();" onclick="showNext($(this));">修改</a>
    		<div class="hide">				
    			<?php echo $form->dropDownList($model,'arc_state',Article::model()->generateStateDropdownList()); ?>
    			<?php echo $form->error($model,'arc_state'); ?>
    		</div>		
    	</div>
    	<div class="row">
    		Comments*：&nbsp;&nbsp;<span id="commentlabel">Allow</span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void();" onclick="showNext($(this));">修改</a>
    		<div class="hide">				
    			<?php echo $form->dropDownList($model,'arc_iscomment',Article::model()->generateCommentStateDropdownList()); ?>
    			<?php echo $form->error($model,'arc_iscomment'); ?>
    		</div>		
    	</div>
    	<div class="row">
    		Time*：&nbsp;&nbsp;<span id="timelabel"><?php echo date('Y-m-d H:i:s',time());?></span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void();" onclick="showNext($(this));">修改</a>
    		<div class="hide">
    			<?php echo $form->textField($model,'arc_created',array('value'=>date('Y-m-d H:i:s',time()))); ?>
    			<?php echo $form->error($model,'arc_created'); ?>		
    		</div>
    
    	</div>
    </div>
	<?php $this->endWidget();?>
	<?php
		$this->beginWidget('zii.widgets.CPortlet', array(
			'title'=>'',
		));
	?>	
		<div class="box-content" style="height:30px;">
			<?php if($model->isNewRecord):?>
				<button type="submit" id="arc_submit" class="right" >Create</button> 
			<?php else:?>
				<button type="submit" id="arc_submit" class="right" >Update</button> 
			<?php endif;?>	
		</div>
	<?php $this->endWidget();?>
	
	<?php
		$this->beginWidget('zii.widgets.CPortlet', array(
			'title'=>'Tags*',
		));
	?>	
    <div class="row">
    	<?php echo $form->textField($model,'arc_tags',array('style'=>'width:60%;')); ?>
    	<button type="button" id="get_tag" class="right" onclick="getTag();" >Tags</button>
    	<input type="hidden" name="Article[arc_cid]" id="Article_arc_cid" value="<?php $result = Category::model()->getCategoryDeepZeroInfo(Category::CATEGORY_NEWS); echo $result['id'];?>" /> 
    	<?php echo $form->error($model,'arc_tags'); ?>
    </div>	    
	<?php $this->endWidget();?>	
<!-- 
	<?php
		$this->beginWidget('zii.widgets.CPortlet', array(
			'title'=>'Category',
		));
	?>
   	<div class="row">
    	<?php 
    		$this->widget('application.components.category.CategoryList',array('view'=>'list','type'=>Category::CATEGORY_NEWS));
    	?>
    	&nbsp;&nbsp;<span id="categorylabel"><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void();" onclick="showNext($(this));">增加分类</a>
            
       	<div class="hide">	<br />
               <div class="column1" style="margin:0px;">
                   <?php echo $form->dropDownList($model,'arc_cid',Category::model()->getCategoryDropdownList(Category::CATEGORY_NEWS)); ?>
                   <?php echo $form->error($model,'arc_cid'); ?>
               </div>
	           <div class="column2"  style="padding:0px;">
                  <input type="hidden" id="Article_arc_cids" name="Article[arc_cids]"/>	
        		  <input type="text" id="categoryName" name="categoryName" />	
               </div>
                <br />
                <button id="add_category" type="button">Add</button>    		
    	</div>	    
    </div>

	<?php $this->endWidget();?>
 -->
</div>
<?php $this->endWidget(); ?>
